precision mediump float;
uniform sampler2D u_texture; 
uniform sampler2D u_texture0; 
uniform sampler2D u_texture1; 
uniform sampler2D u_texture2; 
varying vec2 v_uv; 
uniform vec3 u_camera_pos;
varying vec4 v_posW;
varying float MultiplicationFactor;
void main()
{
	vec2 newUV = v_uv * MultiplicationFactor;
	vec4 hColor = texture2D(u_texture, v_uv);
	vec4 color1 = texture2D(u_texture0, v_uv*newUV);
	vec4 color2 = texture2D(u_texture1, v_uv*newUV);
	vec4 color3 = texture2D(u_texture2, v_uv*newUV);
	
	
	vec4 fogColor = vec4(1.0, 1.0, 1.0, 1.0);
	vec4 camera_pos = vec4(u_camera_pos, 1.0);
	vec4 v_distance =  camera_pos - v_posW;
	float f_distance = length(v_distance);	
	float  lerpValue = clamp( ( f_distance - 10.0)/100.0 , 0.0, 1.0);
	vec4 texColor = (hColor.r * color1 + hColor.g * color2 + hColor.b * color3)/ (hColor.r + hColor.g + hColor.b);

	gl_FragColor = lerpValue * fogColor + (1.0 - lerpValue) * texColor;
	

}
